//
//  TimelineViewController.swift
//  gamlify
//
//  Created by Admin on 2024/12/9.
//

import UIKit

class TimelineViewController: UIViewController {

    private var moodEntries: [(mood: String, time: String, entry: String, image: UIImage?, tags: [String])] = [
        (mood: "happy", time: "12:01", entry: "Today feels particularly heavy, as if the world has lost its spark and everything around me is shrouded...", image: UIImage(named: "autumn_leaves"), tags: ["Courage +2", "Creativity +2", "Discipline +2"]),
        (mood: "happy", time: "12:01", entry: "Today feels particularly heavy, as if the world has lost its spark and everything around me is shrouded...", image: UIImage(named: "autumn_leaves"), tags: ["Courage +2", "Creativity +2", "Discipline +2"]),
        (mood: "happy", time: "12:01", entry: "Today feels particularly heavy, as if the world has lost its spark and everything around me is shrouded...", image: UIImage(named: "autumn_leaves"), tags: ["Courage +2", "Creativity +2", "Discipline +2"]),
        (mood: "happy", time: "12:01", entry: "Today feels particularly heavy, as if the world has lost its spark and everything around me is shrouded...", image: UIImage(named: "autumn_leaves"), tags: ["Courage +2", "Creativity +2", "Discipline +2"]),
    ]
    
    private lazy var tableView: UITableView = {
        let tableView = UITableView()
        tableView.register(GamAICell.self, forCellReuseIdentifier: "MoodEntryCell")
        tableView.delegate = self
        tableView.dataSource = self
        tableView.separatorStyle = .none
        tableView.backgroundColor = .clear
        return tableView
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()

        view.addSubview(tableView)
        tableView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        
        // 底部给tabview增加内容偏移量，防止内容被悬浮的tabbar遮挡
        let inset = UIEdgeInsets(top: 0, left: 0, bottom: AppDimensions.shared.tabBarTopToSafeArea, right: 0)
        tableView.contentInset = inset
    }
}

// MARK: - UITableViewDelegate, UITableViewDataSource
extension TimelineViewController: UITableViewDelegate, UITableViewDataSource {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return moodEntries.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "MoodEntryCell", for: indexPath) as! GamAICell
        let entry = moodEntries[indexPath.row]
        cell.configure(with: entry.mood, time: entry.time, entry: entry.entry, image: entry.image, tags: entry.tags)
        return cell
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return UITableView.automaticDimension
    }
}
